//
//  RechargeRecordViewController.m
//  YunGou
//
//  Created by macbook on 16/5/18.
//  Copyright © 2016年 macbook. All rights reserved.
//

#import "RechargeRecordViewController.h"
#import "NoMoreDataView.h"
#import "RechargeRecordCell.h"
#import "RechargeRecordModel.h"
#import "NSObject+Tools.h"
#import "NullDataView.h"

@interface RechargeRecordViewController ()
@property (nonatomic,strong)NSMutableArray *dataArray;
@property (nonatomic,strong) NullDataView *nullDataView;
@end

@implementation RechargeRecordViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    _dataArray = [NSMutableArray array];
    [MBProgressHUD showMessage:@"正在加载"];
    [NetWorkTool rechargeRecordWithSuccess:^(id object) {
        [MBProgressHUD hideHUD];
        for (NSDictionary *dict in object[@"data"]) {
            RechargeRecordModel *rechargeModel = [RechargeRecordModel modelWithDict:dict];
            [_dataArray addObject:rechargeModel];
        }
        if (_dataArray.count == 0) {
            [self.view addSubview:self.nullDataView];
            self.tableView.tableFooterView = nil;
        }else{
            if (_nullDataView) {
                [_nullDataView removeFromSuperview];
                _nullDataView = nil;
            }
            NoMoreDataView *footerView = [[NoMoreDataView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, 44)];
            self.tableView.tableFooterView = footerView;
        }
        [self.tableView reloadData];
    } failure:^(NSError *error) {
        
    }];
    
    NoMoreDataView *footerView = [[NoMoreDataView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, 44)];
    self.tableView.tableFooterView = footerView;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return _dataArray.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    RechargeRecordCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
    cell.rechargeRecordModel = _dataArray[indexPath.row];
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 68;
}

#pragma -mark 懒加载
- (NullDataView *)nullDataView{
    if (!_nullDataView) {
        _nullDataView = [NullDataView nullDataView];
        _nullDataView.bounds = self.view.bounds;
    }
    return _nullDataView;
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
